﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class SalaryService : ISalaryService
    {
        private ISalaryDal _salary;
        private IMapper _mapper;
        public SalaryService(ISalaryDal salary, IMapper mapper)
        {
            _salary = salary;
            _mapper = mapper;
        }

        public async Task<int> AddSalaryAsync(decimal salary, int jobId)
        {
            return await _salary.AddAsync(new Salary 
            {
                Salary1 = salary,
                JobsId = jobId
            });
        }

        public async Task<int> DeleteSalaryAsync(int id)
        {
            var data = await _salary.QueryAsync(id);
            return data == null ? -1 : await _salary.DeleteAsync(data);
        }

        public async Task<int> EditSalaryAsync(int id, decimal salary, int jobId)
        {
            var data = await _salary.QueryAsync(id);
            if (data == null)
                return -1;
            data.Salary1 = salary;
            data.JobsId = jobId;
            return await _salary.EditAsync(data);
        }

        public async Task<List<SalaryDto>> QuerySalaryAllAsync()
        {
            var data = await _salary.QueryAsync();
            return _mapper.Map<List<Salary>,List<SalaryDto>>(data);
        }

        public async Task<SalaryDto> QuerySalaryByIdAsync(int id)
        {
            var data = await _salary.QueryAsync(id);
            return _mapper.Map<Salary,SalaryDto>(data);
        }
    }
}
